###########################################################################
#	$Id: engineModule.p 17 2009-04-27 04:11:49Z donbeave $
###########################################################################

@CLASS
engineModule

@USE
concept/conceptModule.p

@BASE
conceptModule

@OPTIONS
locals

#----- Constructor -----

@create[hshOptions]
## hshOptions.request.domainName
## hshOptions.request.URI
## hshOptions.request.language
  ^cleanMethodArgument[hshOptions]

  ^BASE:create[$hshOptions]

  $self._requestOptions[^hash::create[$hshOptions.request]]

  $oSite[^STORAGE.getSiteByID[$DOMAIN.SiteID]]

  ^if(!($oSite is engineSiteItem)){
    ^pfAssert:fail[Site [ID: $DOMAIN.SiteID] not found.]
  }

  ^STORAGE.useSite[$oSite]

#----- Properties -----

@GET_DOMAIN[]
  ^if(def $_requestOptions.domainName){
    $sDomain[$_requestOptions.domainName]
  }{
     $sDomain[$env:SERVER_NAME]
   }
  $result[^STORAGE.getDomainByName[$sDomain]]

  ^if(!($result is engineDomainItem)){
    ^pfAssert:fail[Domain "$sDomain" not found.]
  }

@GET_SITE[]
  $result[$STORAGE.SITE]

#----- Fabriques -----

@defaultStorageFactory[hshStorageOptions]
  ^use[engine/storages/engineStorageSQL.p]
  ^cleanMethodArgument[hshStorageOptions]
# adding default fields
  ^hshStorageOptions.union[
    $.sql[$CSQL]
  ]
  $hshStorageOptions.concept[$self]
  $result[^engineStorageSQL::create[$hshStorageOptions]]